<?php

declare(strict_types=1);

namespace App\Job;

use Hyperf\AsyncQueue\Job;
use App\Model\Order;
use App\Model\OrderGood;
use Hyperf\DbConnection\Db;

class SpikeRollBackExampleJob extends Job
{
    public $params;
    
    /**
     * 任务执行失败后的重试次数，即最大执行次数为 $maxAttempts+1 次
     */
    protected int $maxAttempts = 2;

    public function __construct($params)
    {
        $this->params = $params;
    }

    public function handle()
    {
    	//删除orderGood表
    	// $orderGood = OrderGood::query()->where('order_id', $this->params)->get();
     //    if (!empty($orderGood)) {
     //       $delGood = [];
     //       foreach ($orderGood as $k => $v) {
     //           array_push($delGood, $v['id']);
     //       }
     //       if (!empty($delGood)) {
     //           OrderGood::destroy($delGood);
     //       }
     //    }
		// Db::connection('default')->table('order_good')->where('order_id', $this->params)->delete();
        OrderGood::query()->where('order_id', $this->params)->delete();

        //删除order表
        Order::query()->where('order_id', $this->params)->delete(); 
    }
}
